package com.b2bpsssm.controller.material.account;

import com.b2bpsssm.common.R;
import com.b2bpsssm.pojo.Account;
import com.b2bpsssm.service.AccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@Api(value = "账户页面",tags = "账户接口Api")
//@RequestMapping("/account")
public class AccountController {

    @Autowired
    private AccountService accountService;


//    @RequestMapping(value = "url路径",method = RequestMethod.GET)
//    @ApiOperation(value = "主标题",notes = "主标题描述",httpMethod = "get/post",response = R.class)
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "page",value = "当前页码",required = true ),
//            @ApiImplicitParam(name = "limit",value = "每页条数",required = true )
//    })


    /*
    * 账户页页码每页条数查询
    * */
    @RequestMapping(value = "/account/queryAccountByPageLimit",method = RequestMethod.GET)
    @ApiOperation(value = "查询账户",notes = "依靠当前页码和每页条数进行查询",httpMethod = "",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "当前页码",required = true ),
            @ApiImplicitParam(name = "limit",value = "每页条数",required = true )
    })
    @ResponseBody
    public R queryAccountByPageLimit(Integer page, Integer limit){
        R r = accountService.queryAccountByPageLimit(page, limit);
        return r;

    }


    /*
    * 新增账户
    * */
    @RequestMapping(value = "/account/addAccount",method = RequestMethod.POST)
    @ApiOperation(value = "新增账户",notes = "新增并保存",httpMethod = "post",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "acc_Create_Date",value = "建账日期",required = true ),
            @ApiImplicitParam(name = "acc_Id",value = "账户编号",required = true ),
            @ApiImplicitParam(name = "acc_Name",value = "账户名称",required = true ),
            @ApiImplicitParam(name = "acc_Cla_Id",value = "账户类型",required = true ),
            @ApiImplicitParam(name = "acc_Opening_Balance",value = "期初余额（元）",required = true ),
            @ApiImplicitParam(name = "acc_Remark",value = "收款备注",required = false ),
    })
    @ResponseBody
    public R addAccount(@RequestBody Account account){
       return accountService.addAccount(account);
    }

    /*
     * 编辑账户
     * */
    @RequestMapping(value = "/account/updateAccount",method = RequestMethod.POST)
    @ApiOperation(value = "修改账户",notes = "保存",httpMethod = "post",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "acc_Create_Date",value = "建账日期",required = true ),
            @ApiImplicitParam(name = "acc_Id",value = "账户编号(前端锁定,禁止修改)",required = true ),
            @ApiImplicitParam(name = "acc_Name",value = "账户名称",required = true ),
            @ApiImplicitParam(name = "acc_Cla_Id",value = "账户类型",required = true ),
            @ApiImplicitParam(name = "acc_Opening_Balance",value = "期初余额（元）",required = true ),
            @ApiImplicitParam(name = "acc_Remark",value = "收款备注",required = false ),
    })
    @ResponseBody
    public R updateAccount(@RequestBody Account account){
        return accountService.updateAccount(account);
    }

    /*
     * 删除账户
     * */
    @RequestMapping(value = "/account/delAccount",method = RequestMethod.POST)
    @ApiOperation(value = "删除账户",notes = "删除",httpMethod = "post",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "acc_Id",value = "账户编号",required = true ),
    })
    @ResponseBody
    public R delAccount(@RequestBody Account account){
        return accountService.delAccount(account);
    }

    /*
     * 禁用账户
     * */
    @RequestMapping(value = "/account/disabledAccount",method = RequestMethod.POST)
    @ApiOperation(value = "删除账户",notes = "删除",httpMethod = "post",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "acc_Id",value = "账户编号",required = true ),
    })
    @ResponseBody
    public R disabledAccount(@RequestBody Account account){
        return accountService.disabledAccount(account);
    }


    /*
     * 关键字搜索账户
     * */
    @RequestMapping(value = "/account/selAccountLikeName",method = RequestMethod.GET)
    @ApiOperation(value = "搜索账户",notes = "以账户名进行关键字查询",httpMethod = "get",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "当前页码",required = true ),
            @ApiImplicitParam(name = "limit",value = "每页条数",required = true ),
            @ApiImplicitParam(name = "acc_Name",value = "账户名称",required = true )

    })
    @ResponseBody
    public R selAccountLikeName(Integer page, Integer limit, String acc_Name){
//        R r = new R();
//        r.setCode(200);
//        r.setData(666);
//        r.setMassage("success");
        R r = accountService.selAccountLikeName(page, limit,acc_Name);
        return r;
    }




}
